using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PrintEffect : MonoBehaviour
{

	public float printDuration = 0.2f;
	List<GameObject> gameObjectSort;
	int mOffset = 0;
	float mNextPrint = 0f;

	void Update ()
	{
		if (gameObjectSort == null) {
			gameObjectSort = GameObjectUtils.getChildrenGameObjectSort (gameObject);
			initPrint ();
		}
		
		if (mOffset < gameObjectSort.Count) {
			if (mNextPrint <= Time.time) {
				mNextPrint = Time.time + (float)printDuration;
				setPrintActive (gameObjectSort [mOffset++]);
			}
			
		} else {
			completePrint ();
		}
	}
	
	virtual protected void initPrint ()
	{
		foreach (GameObject go in gameObjectSort) {
			go.SetActive (false);
		}
	}
	
	virtual protected void setPrintActive (GameObject go)
	{
		go.SetActive (true);
	}
	
	virtual protected void completePrint ()
	{
		Destroy (this);
	}
}
